package com.hong.concurrent.chapter9;

import java.util.LinkedList;

/**
 * @Author csh
 * @Description
 * @Date 2018/7/5 21:18
 */
public class RequestQueue {

    private final LinkedList<Request> queue=  new LinkedList<>();

    public Request getRequest(){
        synchronized (queue){
            while (queue.size()<0){
                try {
                    queue.wait();
                }catch (InterruptedException e){
                    return null;
                }
            }
            Request request = queue.removeFirst();
            return request;
        }
    }

    public  void putRequest(Request request){
        synchronized (queue){
            queue.addLast(request);
            queue.notifyAll();
        }
    }
}
